package com.example.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.newpartsmanage;
import com.example.demo.mapper.newpartsmanageMapper;
import com.example.demo.service.NewpartsmanageService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class NewpartsmanageServiceImpl extends ServiceImpl<newpartsmanageMapper, newpartsmanage> implements NewpartsmanageService {
    @Resource
    private newpartsmanageMapper newpartsmanageMapper;//注入

    @Override
    public String Storage(@RequestBody newpartsmanage newpartsmanage)//输入数据插入新件视图
    {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");//填入系统时间
        Date date = new Date();
        newpartsmanage.setWtime(dateFormat.format(date));
        if(newpartsmanageMapper.Storage(newpartsmanage)==1)//判断是否插入成功
        {
            return "入库成功";
        }
        else {return "入库失败";}
    }
    @Override
    public List querynewpartsmanage(@RequestBody newpartsmanage newpartsmanage)//输入新件主键查询新件信息
    {
        return newpartsmanageMapper.selectNewkey(newpartsmanage);
    }
    @Override
    public String Outbound(int newkey)//输入查询条件
    {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
        Date date = new Date();
        if(newpartsmanageMapper.Outbound(newkey,dateFormat.format(date))==1)//判断是否修改成功
        {
            return "出库成功";
        }
        else {return "出库失败";}
    }
    @Override
    public String update(@RequestBody newpartsmanage newpartsmanage)
    {
        if(newpartsmanageMapper.updatenewpartsmanage(newpartsmanage)==1)//判断是否修改成功
        {
            return "修改成功";
        }
        else {return "修改失败";}
    }
}
